package cn.jeeweb.web.modules.sys.service.impl;

import cn.jeeweb.common.mybatis.mvc.service.impl.CommonServiceImpl;
import cn.jeeweb.common.mybatis.mvc.wrapper.EntityWrapper;
import cn.jeeweb.web.modules.sys.entity.SysGroup;
import cn.jeeweb.web.modules.sys.entity.SysUserGroup;
import cn.jeeweb.web.modules.sys.mapper.SysGroupMapper;
import cn.jeeweb.web.modules.sys.service.ISysGroupService;
import cn.jeeweb.web.modules.sys.service.ISysUserGroupService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Transactional
@Service("sysGroupService")
public class SysGroupServiceImpl extends CommonServiceImpl<SysGroupMapper, SysGroup> implements ISysGroupService {

    @Autowired
    ISysUserGroupService sysUserGroupService;

    public boolean deleteById(String json){
        super.deleteById(json);
        JSONObject jsonObject = JSON.parseObject(json);
        String groupId = jsonObject.getString("id");
        EntityWrapper<SysUserGroup> entityWrapper = new EntityWrapper<>(SysUserGroup.class);
        entityWrapper.eq("groupId",groupId);
        return sysUserGroupService.delete(entityWrapper);
    }

    public SysGroup insertAndSelect(String json){
        SysGroup sysGroup = JSON.parseObject(json,SysGroup.class);
        String[] array = sysGroup.getOrganizationIds();
        if(array != null && array.length > 0){
            for(String val : array){
                SysGroup group = new SysGroup();
//                group.setName();
            }
        }
        return new SysGroup();
    }

}
